/**
 * Created by yangfan on 2016/10/18.
 */
define(['config/appregister',"i18n","business/personMine/services/httpServices","business/services/components"],function(app,i18n,personHttpService){
    app.controller('othersVideosCtrl', function($scope,$state,$stateParams) {
        $scope.i18n = i18n;
        $scope.everPageShow = [30,50,100];
        // 切换title
        $scope.isDataChecked = true;
        $scope.isThesisChecked = false;
        $scope.tableTitle = ["课程信息","培训机构","最后学习时间","操作"];
        $scope.titleNavation = [
            {title:"我评论的",type:"myComment"},
            {title:"评论我的",type:"commented"},
        ];
        $scope.isShowCurrent = [];
        $scope.isShowCurrent[0] = true;
        $scope.isMyComment = true;
        $scope.byComment = false;
        $scope.dialogModel = {
            title:"",
            content:"您确定要退出吗?",
            isShow:false,
            align:"left",
            confirm:function(){
                cancelCourseEnroll();
            }
        };
        if( !angular.isUndefined($stateParams.userId)){
            $scope.userId = $stateParams.userId;
            $scope.$emit('getOthersId',{userId:$scope.userId})
        }

        //待切换加载数据
        $scope.checkTitle = function(type,index){
            $scope.isShowCurrent = [];
            $scope.isShowCurrent[index] = true;
            if(index == 0){
                $scope.isMyComment = true;
                $scope.byComment = false;
                init();
            }else if(index ==1){
                $scope.isMyComment = false;
                $scope.byComment = true;
                getCommentForMe()
            }
        };


        $scope.isCurrent = [];
        $scope.isCurrent[0] = "bold";
        $scope.listParams = {
            pageNo:1,
            pageSize:10
        };
        function getPgination(){
            $scope.paginationConf = {
                currentPage: $scope.listParams.pageNo,
                totalItems: $scope.totalItem,
                //每页预览条数
                itemsPerPage: $scope.listParams.pageSize,
                //分页总数
                numberOfPages:Math.ceil($scope.totalItem/$scope.listParams.pageSize),
                // 实际分页长度
                pagesLength: 5,
                perPageOptions: [10, 20, 30, 40, 50],
                onChange: function () {
                    $scope.list = [];
                    $scope.listParams.pageNo = $scope.paginationConf.currentPage;
                    getMyCourse();
                }

            };
            $scope.everPageShow = $scope.paginationConf.perPageOptions;
        }

         function getMyCourse(){
             var req = {
                 type:"GET",
                 uri:"getHeCourse",
                 data:{
                     pageNo:$scope.listParams.pageNo,
                     pageSize:$scope.listParams.pageSize,
                     userId:$stateParams.userId
                 }
             };
             personHttpService.getMyCourse(req).success(function(response){
                 $scope.$apply(function(){
                     $scope.videos = response.data.list;
                     $scope.totalItem = response.data.Pagination.totalCount;

                     getPgination();
                 });
             }).error(function(){})

         }
        getMyCourse();

        function cancelCourseEnroll(){
            var req = {
                type:"GET",
                uri:"cancelCourseEnroll",
                data:{
                    //删不准
                  courseId :$scope.curCourseId+"aaa",
                }
            };
            personHttpService.cancelCourseEnroll(req).success(function(response){
                $scope.$apply(function(){
                    $scope.dialogModel.isShow =false;
                });

            }).error(function(){
                $scope.$apply(function(){
                    $scope.dialogModel.isShow =false;
                });
            })

        }

        //点击退出
        $scope.back = function(item){
            $scope.curCourseId = item.courseId;
            $scope.dialogModel.title = item.title ;
            $scope.dialogModel.isShow =true;
        };
        //改变每页预览条数
        $scope.changeItemsPerPage = function(item ,index){
            $scope.isCurrent = [];
            $scope.isCurrent[index] = "bold";

            $scope.listParams.pageNo = 1;
            $scope.listParams.pageSize = item;
            $scope.paginationConf.itemsPerPage = item;
            $scope.paginationConf.numberOfPages = parseInt($scope.totalItem/$scope.listParams.pageSize);
            //  $scope.$broadcast("numberOfPagesChange",{});
            init();
        }
    })
});